layui.use(['common','layer','table','form',],function(){
	var $ = layui.$,
    	layer = layui.layer,
    	form = layui.form,
    	common = layui.common,
    	table = layui.table;
	
	var  tableIns = table.render({
		elem: '#permissionsList', //指定原始表格元素选择器（推荐id选择器）
		cols: [
			[{
				field: 'permissionId',
				align:'center',
				title: 'ID',
				sort: true,
			}, {
				field: 'name',
				align:'center',
				title: '名称',
				align: 'center',
			}, {
				field: 'permissionValue',
				align:'center',
				title: '权限值',
				align: 'center',
			}, {
				field: 'uri',
				align:'center',
				title: '路径',
				align: 'center',
			}, {
				field: 'icon',
				align:'center',
				title: '图标',
				sort: true,
				align: 'center',
			}, {
				field: 'status',
				align:'center',
				title: '状态',
				templet: '#statusTpl',
				align: 'center',
			}, {
				align:'center',
				title: '操作',
				toolbar: '#permissionsBar'
			}]
		], //设置表头
		url:'/systemsetup/permissionsmanage/permissions/findPagingQuery',
		page: true,
		loading: true,
		limits: [10,30,60,90,150,300],
		limit: 10 //默认采用60
    });
	
	//监听工具条
    table.on('tool(permissionsList)', function(obj){
	    	var data = obj.data;
	    	console.log(data.id);
	    	if(obj.event === 'detail'){
	    		layer.open({
	    			  type: 2,
	    			  area: ['600px', '440px'], //宽高
	    			  content: "/systemsetup/permissionsmanage/permissions/detailIndex?id="+data.permissionId,
	    			  end: function(){
	    				tableIns.reload();
	    			  }
	      	});
	    	} else if(obj.event === 'del'){
	    		
	    	} else if(obj.event === 'edit'){
	    		layer.open({
	    			  type: 2,
	    			  area: ['600px', '440px'], //宽高
	    			  content: "/systemsetup/permissionsmanage/permissions/editIndex?id="+data.permissionId,
	    			  end: function(){
	    				tableIns.reload();
	    			  }
	      	});
	    	}
    });
	
	
	
	
	common.larryCmsLoadJq('/LarryMS/business/common/ztree/js/jquery.ztree.all.js', function() {
		var zTreeObj,
		setting = {
				
				data: {  
                    simpleData: {  
                        enable: true  
                    }
                },
			callback: {
				onClick: zTreeOnClick
			}
		}
		var $j = jQuery.noConflict();
		
		$.post("/systemsetup/permissionsmanage/permissions/selectPermissions","",function(result){
			zTreeObj = $j.fn.zTree.init($("#treeDemo"), setting, result.data);
		});
		
		function zTreeOnClick(event, treeId, treeNode) {
			tableIns.reload({
		    	  where: { //设定异步数据接口的额外参数，任意设
		    		  pid: treeNode.id
		    	  },
		    	  page: {
		    	    curr: 1 //重新从第 1 页开始
		    	  }
		    	});
		};
	});
	$('#addPermissions').on('click', function() {
		 layer.open({
		      type: 2,
		      shadeClose: true,
		      title: '添加权限',
		      maxmin: true, //开启最大化最小化按钮
		      area: ['893px', '450px'],
		      content: '/systemsetup/permissionsmanage/permissions/addIndex',
		    	  end: function () {
			    	 tableIns.reload();
		      },
		 });
	 });
	
	//监听锁定操作
	 form.on('checkbox(lockDemo)', function(obj){
	    $.post("/systemsetup/permissionsmanage/permissions/permissionsByStatus",{"id":this.value},function(result){
	    		if (result.status == 200) {
	    			layer.msg(result.msg);
			} else {
				layer.msg(result.msg);
			}
	    })
	    
	    
	    
	  });
	
});